< previous page page_282 next page >

Page 282
LISTING 10.4. DAOEX4.TXTCHECKING FOR THE EOF OR BOF CONDITIONS.

8694cbadb9b1ef7075903f6f95fc1db2.gif
 1: Private Sub cmdNext_Click()
 2:     MyDyn.MoveNext
 3:     If MyDyn.EOF Then
 4:         MsgBox Last record displayed, vbInformation, App.Title
 5:         MyDyn.MoveLast
 6:     End If
 7:     Call DisplayFields
 8: End Sub
 9:
10: Private Sub cmdPrevious_Click()
11:     MyDyn.MovePrevious
12:      If MyDyn.BOF Then
13:         MsgBox First record displayed, vbInformation, App.Title
14:         MyDyn.MoveFirst
15:     End If
16:    Call DisplayFields
17: End Sub

Besides displaying the data on a form, you can use the ActiveX Data Objects to modify, add, or delete data in the database. The AddNew method used to add a new record to a recordset doesn't actually add the record; instead, it clears the copy buffer to allow data for the new record to be input. To add the record physically after you put data into the record's fields, you use the Update method. Listing 10.5 shows how to use the AddNew method to add a new record to the recordset.
LISTING 10.5. DAOEX5.TXTADDING A RECORD TO THE RECORDSET.

8694cbadb9b1ef7075903f6f95fc1db2.gif
1: Private Sub cmdAdd_Click()
2:     MyDyn.AddNew
3:     Call SetFields
4:     MyDyn.Update
5: End Sub

Caution
Because the new data isn't added to the database until an
Update method is executed, reusing the AddNew method or moving the record pointer with any Move or Find method will clear the copy buffer, and any data that has been entered will be lost.

In the same way a routine was used to move the data from the recordset to the controls, a routine should be used to move the data from the controls to the recordset.

 
< previous page page_282 next page >

If you like this book, buy it!